#!/bin/sh
set -e
start(){
#定义项目路径
DIR=/home/tslsmart/edgebox/app
#定义进程id
PID=$(ps aux|grep java|grep $1 |grep -v grep|awk '{print $2}')
echo "$PID"
echo "获取到当前PID为: ${PID}"
# 杀掉对应的进程，如果pid不存在，则不执行
if [ -n "${PID}" ] ; then
    kill -9 ${PID}
fi
# 进入项目所在目录
cd $DIR
nohup java -jar os-box-app.jar --spring.application.name=$1 --server.port=$2 >/dev/null 2>&1 &
PID=$(ps aux|grep java|grep $1 |grep -v grep|awk '{print $2}')
if [ -n "${PID}" ] ; then
echo "===========app running==========="
else
echo "===========app start fail==========="
fi
}

stop(){
#定义进程id
PID=$(ps aux|grep java|grep $1 |grep -v grep|awk '{print $2}')
echo "$PID"
echo "获取到当前PID为: ${PID}"
# 杀掉对应的进程，如果pid不存在，则不执行
if [ -n "${PID}" ] ; then
    kill -9 ${PID}
    echo "===========app shutdown==========="
fi

}

case "$1" in
  "start")
    start $2 $3;;
  "stop")
    stop $2 $3;;
   *)
esac

